import sys
from PIL import Image

def merge_images_with_vertical_bar(image_path1, image_path2):
    # 打开两张图片
    image1 = Image.open(image_path1)
    image2 = Image.open(image_path2)

    # 获取图片1和图片2的宽度和高度
    width1, height1 = image1.size
    width2, height2 = image2.size

    # 计算拼接后的图片宽度和高度，中间留出10px的空白区域
    new_width = width1 + width2 + 20  # 竖条宽度为10px
    new_height = max(height1, height2)

    # 创建一个新的空白画布
    new_image = Image.new('RGB', (new_width, new_height), color='white')

    # 计算粘贴位置，留出10px宽的空白区域
    position1 = (0, (new_height - height1) // 2)
    position2 = (width1 + 20, (new_height - height2) // 2)  # 图片2右移10px

    # 将两张图片粘贴到新画布上
    new_image.paste(image1, position1)
    new_image.paste(image2, position2)

    # 返回合成后的图片对象
    return new_image

if __name__ == "__main__":
    print(sys.argv)
    if len(sys.argv) != 4:
        print("Usage: python script_name.py image1_path image2_path")
    else:
        image_path_1 = sys.argv[1] + sys.argv[3]
        image_path_2 = sys.argv[2] + sys.argv[3]
        result_image = merge_images_with_vertical_bar(image_path_1, image_path_2)

        # 显示合成后的图片
        #result_image.show()  # 显示图片
        result_image.save(sys.argv[1] +'-'+ sys.argv[2] + sys.argv[3])  # 保存图片，取消注释以保存图片到本地
